home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / amusemen / nolan-1.1 / nolan.tar / screen.c < prev    next >
C/C++ Source or Header  |  1994-04-25  |  4KB  |  170 lines

  1. /*****************************************************************************
  2.  
  3. NAME
  4.    screen.c --- screen-handling primitives for the quiz program
  5.  
  6. *****************************************************************************/
  7. /*LINTLIBRARY*/
  8. #include <stdlib.h>
  9. #ifdef NCURSES
  10. #include <ncurses.h>
  11. #else
  12. #include <curses.h>
  13. #endif /* NCURSES */
  14. #ifdef CURSES
  15. #include <string.h>
  16. #include <stdarg.h>
  17. #endif /* CURSES */
  18.  
  19. #ifndef A_UNDERLINE    /* BSD curses */
  20. #define    cbreak    crmode
  21. #define    saveterm savetty
  22. #define    resetterm resetty
  23. #define    nocbreak nocrmode
  24. #define strchr    index
  25. #endif /* !A_UNDERLINE */
  26.  
  27. void initscreen(void)
  28. /* initialize screen routines and clear screen */
  29. {
  30. #ifdef CURSES
  31.     (void) initscr();
  32.     (void) saveterm();
  33.     (void) nonl();
  34.     (void) cbreak();
  35.     (void) noecho();
  36.  
  37. #ifdef A_COLOR
  38.     start_color();
  39.  
  40.     init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK);
  41.     init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
  42.     init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK);
  43.     init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
  44.     init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
  45.     init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
  46.     init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
  47.     init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
  48. #endif /* A_COLOR */
  49.  
  50.     (void) clear();
  51. #endif /* CURSES */
  52. }
  53.  
  54. void endscreen(void)
  55. /* de-initialize screen routines */
  56. {
  57. #ifdef CURSES
  58.     (void)refresh();
  59.     (void)resetterm();
  60.     (void)echo();
  61.     (void)endwin();
  62. #endif /* CURSES */
  63. }
  64.  
  65. void clearscreen(void)
  66. /* return the x index to start a string at to center it on screen */
  67. {
  68. #ifdef CURSES
  69.     clear();
  70. #endif /* CURSES */
  71. }
  72.  
  73. void sputs(char *prompt)
  74. /* present a next-page prompt and wait for any key */
  75. {
  76. #ifdef CURSES
  77.     addstr(prompt);
  78. #endif /* CURSES */
  79. }
  80.  
  81. void scprintf(char *format, int arg1)
  82. /* present a next-page prompt and wait for any key */
  83. {
  84. #ifdef CURSES
  85.     printw(format, arg1);
  86. #endif /* CURSES */
  87. }
  88.  
  89. void sputc(char ch)
  90. /* put character to screen, advance cursor */
  91. {
  92. #ifdef CURSES
  93.     addch(ch);
  94. #endif /* CURSES */
  95. }
  96.  
  97. char sgetch(void)
  98. /* get a character, no echo */
  99. {
  100. #ifdef CURSES
  101.     return(getch());
  102. #endif /* CURSES */
  103. }
  104.  
  105. void screenloc(int *py, int *px)
  106. /* get the current cursor location */
  107. {
  108. #ifdef CURSES
  109.     getyx(stdscr, *py, *px);
  110. #endif /* CURSES */
  111. }
  112.  
  113. void movecursor(int y, int x)
  114. /* move the cursor to a given position */
  115. {
  116. #ifdef CURSES
  117.     move(y, x);
  118. #endif /* CURSES */
  119. }
  120.  
  121. #ifdef CURSES
  122. /*
  123.  * Highlight-handling code
  124.  */
  125. static char *attrnames = "xgrcwmbyXGRCWMBY";
  126. static int colorpairs[] =
  127. {
  128.     COLOR_PAIR(COLOR_BLACK),
  129.     COLOR_PAIR(COLOR_GREEN),
  130.     COLOR_PAIR(COLOR_RED),
  131.     COLOR_PAIR(COLOR_CYAN),
  132.     COLOR_PAIR(COLOR_WHITE),
  133.     COLOR_PAIR(COLOR_MAGENTA),
  134.     COLOR_PAIR(COLOR_BLUE),
  135.     COLOR_PAIR(COLOR_YELLOW),
  136.     COLOR_PAIR(COLOR_BLACK) | A_BOLD,
  137.     COLOR_PAIR(COLOR_GREEN) | A_BOLD,
  138.     COLOR_PAIR(COLOR_RED) | A_BOLD,
  139.     COLOR_PAIR(COLOR_CYAN) | A_BOLD,
  140.     COLOR_PAIR(COLOR_WHITE) | A_BOLD,
  141.     COLOR_PAIR(COLOR_MAGENTA) | A_BOLD,
  142.     COLOR_PAIR(COLOR_BLUE) | A_BOLD,
  143.     COLOR_PAIR(COLOR_YELLOW) | A_BOLD,
  144. };
  145. #endif /* CURSES */
  146.  
  147. int attrok(char attr)
  148. /* is a given attribute supported? */
  149. {
  150. #ifdef CURSES
  151.     return(strchr(attrnames, attr) != (char *)NULL);
  152. #endif /* CURSES */
  153. }
  154.  
  155. void sattrset(char attr)
  156. /* set the screen attribute indicated by a given character */
  157. {
  158. #ifdef CURSES
  159.     attrset(colorpairs[strchr(attrnames, attr) - attrnames]);
  160. #endif /* CURSES */
  161. }
  162.  
  163. char *username(void)
  164. /* get name of user */
  165. {
  166.     return(getlogin());
  167. }
  168.  
  169. /* screen.c ends here */
  170.